function showPlayFrame(args)
	aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture1"))
	aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
	aniPic.start(aniPic)

	if(picAni == 0) then
	picAni = 1
	end

    CEGUI.WindowManager:getSingleton():getWindow("Root/Background/PlayFrame"):setVisible(true)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/AchievementFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/SettingFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/ExitFrame"):setVisible(false)
end

function showAchievementFrame(args)
	if(picAni == 1) then
	aniPic.stop(aniPic)
	aniMgr:destroyAnimationInstance(aniPic)
	end
    CEGUI.WindowManager:getSingleton():getWindow("Root/Background/PlayFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/AchievementFrame"):setVisible(true)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/SettingFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/ExitFrame"):setVisible(false)
end

function showSettingFrame(args)
	if(picAni == 1) then
	aniPic.stop(aniPic)
	aniMgr:destroyAnimationInstance(aniPic)
	end
    CEGUI.WindowManager:getSingleton():getWindow("Root/Background/PlayFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/AchievementFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/SettingFrame"):setVisible(true)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/ExitFrame"):setVisible(false)
end

function showExitFrame(args)
	if(picAni == 1) then
	aniPic.stop(aniPic)
	aniMgr:destroyAnimationInstance(aniPic)
	end
    CEGUI.WindowManager:getSingleton():getWindow("Root/Background/PlayFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/AchievementFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/SettingFrame"):setVisible(false)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/ExitFrame"):setVisible(true)
end

function openGameFrame(args)
	ani.stop(ani)
	--aniMgr:destroyAnimationInstance(ani)
	aniPic.stop(aniPic)
	--aniMgr:destroyAnimationInstance(aniPic)
	aniMgr:destroyAllInstancesOfAnimation(aniMgr:getAnimation("HighLight"))
	aniMgr:destroyAllInstancesOfAnimation(aniMgr:getAnimation("LowLight"))


	PapaBallSceneManager:getSingleton():setScene("GameScene")
end

function leftButtonClicked(args)
	aniPic.stop(aniPic)
	level = level + 3
	level = level % 4
	if(level == 0)
	then
		aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture1"))
		aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
		aniPic.start(aniPic)
	elseif(level == 1)
	then
		aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture2"))
		aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
		aniPic.start(aniPic)
	elseif(level == 2)
	then 
		aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture3"))
		aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
		aniPic.start(aniPic)
	elseif(level == 3)
	then
		aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture4"))
		aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
		aniPic.start(aniPic)
	end
end

function rightButtonClicked(args)
	aniPic.stop(aniPic)
	level = level + 1
	level = level % 4
	if(level == 0)
	then
		aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture1"))
		aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
		aniPic.start(aniPic)
	elseif(level == 1)
	then
		aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture2"))
		aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
		aniPic.start(aniPic)
	elseif(level == 2)
	then 
		aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture3"))
		aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
		aniPic.start(aniPic)
	elseif(level == 3)
	then
		aniPic = aniMgr:instantiateAnimation(aniMgr:getAnimation("ChangePicture4"))
		aniPic.setTargetWindow(aniPic,winMgr:getWindow("Root/Background/PlayFrame/GameImage"))
		aniPic.start(aniPic)
	end
end

function closeAchivementFrame(args)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/AchievementFrame"):setVisible(false)
end

function applySetting(args)

end

function cancelSetting(args)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/SettingFrame"):setVisible(false)
end

function closeExitFrame(args)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/ExitFrame"):setVisible(false)
end

function exitGame(args)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/ExitFrame"):setVisible(false)
	
end

function changeVolumeByClick(args)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/SettingFrame"):setVisible(false)
end

function changeVolumeByDrag(args)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/SettingFrame"):setVisible(false)
end

function changeSilent(args)
	CEGUI.WindowManager:getSingleton():getWindow("Root/Background/SettingFrame"):setVisible(false)
end

function highLight4PF(args)
	ani = aniMgr:instantiateAnimation(aniMgr:getAnimation("HighLight"))
	ani.setTargetWindow(ani,winMgr:getWindow("Root/Background/PlayFrame"))
	ani.start(ani)
end

function lowLight4PF(args)
	ani = aniMgr:instantiateAnimation(aniMgr:getAnimation("LowLight"))
	ani.setTargetWindow(ani,winMgr:getWindow("Root/Background/PlayFrame"))
	ani.start(ani)
end

function highLight4AF(args)
	ani = aniMgr:instantiateAnimation(aniMgr:getAnimation("HighLight"))
	ani.setTargetWindow(ani,winMgr:getWindow("Root/Background/AchievementFrame"))
	ani.start(ani)
end

function lowLight4AF(args)
	ani = aniMgr:instantiateAnimation(aniMgr:getAnimation("LowLight"))
	ani.setTargetWindow(ani,winMgr:getWindow("Root/Background/AchievementFrame"))
	ani.start(ani)
end

function highLight4SF(args)
	ani = aniMgr:instantiateAnimation(aniMgr:getAnimation("HighLight"))
	ani.setTargetWindow(ani,winMgr:getWindow("Root/Background/SettingFrame"))
	ani.start(ani)
end

function lowLight4SF(args)
	ani = aniMgr:instantiateAnimation(aniMgr:getAnimation("LowLight"))
	ani.setTargetWindow(ani,winMgr:getWindow("Root/Background/SettingFrame"))
	ani.start(ani)
end

function highLight4EF(args)
	ani = aniMgr:instantiateAnimation(aniMgr:getAnimation("HighLight"))
	ani.setTargetWindow(ani,winMgr:getWindow("Root/Background/ExitFrame"))
	ani.start(ani)
end

function lowLight4EF(args)
	ani = aniMgr:instantiateAnimation(aniMgr:getAnimation("LowLight"))
	ani.setTargetWindow(ani,winMgr:getWindow("Root/Background/ExitFrame"))
	ani.start(ani)
end

-----------------------------------------
-- Script Entry Point
-----------------------------------------
guiSystem = CEGUI.System:getSingleton()
schemeMgr = CEGUI.SchemeManager:getSingleton()
winMgr = CEGUI.WindowManager:getSingleton()
aniMgr = CEGUI.AnimationManager:getSingleton()
level = 1
picAni = 0

-- load our scheme
schemeMgr:create("MySkin.scheme");
-- load our window layout
local root = winMgr:loadWindowLayout("mainFrame.layout")
-- set the layout as the root
guiSystem:setGUISheet(root)
-- set default mouse cursor
guiSystem:setDefaultMouseCursor("MySkinImages", "MouseArrow")

-- load animations
if(isInit~="true" or isInit==nil)
then
aniMgr:loadAnimationsFromXML("myAnimations.xml") 
isInit="true"
end


-- subscribe required events
winMgr:getWindow("Root/Background/PlayButton"):subscribeEvent("Clicked", "showPlayFrame")
winMgr:getWindow("Root/Background/AchievementButton"):subscribeEvent("Clicked", "showAchievementFrame")
winMgr:getWindow("Root/Background/SettingButton"):subscribeEvent("Clicked", "showSettingFrame")
winMgr:getWindow("Root/Background/ExitButton"):subscribeEvent("Clicked", "showExitFrame")
winMgr:getWindow("Root/Background/PlayFrame/StartButton"):subscribeEvent("Clicked", "openGameFrame")
winMgr:getWindow("Root/Background/PlayFrame/LeftButton"):subscribeEvent("Clicked", "leftButtonClicked")
winMgr:getWindow("Root/Background/PlayFrame/RightButton"):subscribeEvent("Clicked", "rightButtonClicked")
winMgr:getWindow("Root/Background/AchievementFrame/ConfirmButton"):subscribeEvent("Clicked", "closeAchivementFrame")
winMgr:getWindow("Root/Background/SettingFrame/ConfirmButton"):subscribeEvent("Clicked", "applySetting")
winMgr:getWindow("Root/Background/SettingFrame/CancelButton"):subscribeEvent("Clicked", "cancelSetting")
winMgr:getWindow("Root/Background/ExitFrame/ConfirmButton"):subscribeEvent("Clicked", "exitGame")
winMgr:getWindow("Root/Background/ExitFrame/CancelButton"):subscribeEvent("Clicked", "closeExitFrame")

winMgr:getWindow("Root/Background/SettingFrame/VolumeBar"):subscribeEvent("Clicked", "changeVolumeByClick")
winMgr:getWindow("Root/Background/SettingFrame/VolumeBar"):subscribeEvent("ThumbTrackEnded", "changeVolumeByDrag")
winMgr:getWindow("Root/Background/SettingFrame/SilentCheckbox"):subscribeEvent("CheckStateChanged", "changeSilent")
winMgr:getWindow("Root/Background/PlayFrame"):subscribeEvent("MouseEnter", "highLight4PF");
--winMgr:getWindow("Root/Background/PlayFrame"):subscribeEvent("MouseLeave", "lowLight4PF");
winMgr:getWindow("Root/Background/AchievementFrame"):subscribeEvent("MouseEnter", "highLight4AF");
--winMgr:getWindow("Root/Background/AchievementFrame"):subscribeEvent("MouseLeave", "lowLight4AF");
winMgr:getWindow("Root/Background/SettingFrame"):subscribeEvent("MouseEnter", "highLight4SF");
--winMgr:getWindow("Root/Background/SettingFrame"):subscribeEvent("MouseLeave", "lowLight4SF");
winMgr:getWindow("Root/Background/ExitFrame"):subscribeEvent("MouseEnter", "highLight4EF");
--winMgr:getWindow("Root/Background/ExitFrame"):subscribeEvent("MouseLeave", "lowLight4EF");
winMgr:getWindow("Root/Background"):subscribeEvent("MouseEnter", "lowLight4PF");
winMgr:getWindow("Root/Background"):subscribeEvent("MouseEnter", "lowLight4AF");
winMgr:getWindow("Root/Background"):subscribeEvent("MouseEnter", "lowLight4SF");
winMgr:getWindow("Root/Background"):subscribeEvent("MouseEnter", "lowLight4EF");

MenuManager:getSingleton():Deactive(true)

